cmake_minimum_required(VERSION 3.8)
project(robot_sim)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(webots_ros2_driver REQUIRED)
find_package(pluginlib REQUIRED)
find_package(control-algorithm REQUIRED)
find_package(general_interface REQUIRED)
find_package(tf2 REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)

# add sim driver library
add_library(webots_driver SHARED
  src/robot_webots_driver.cpp
  src/webots_direct_driver.cpp)
target_include_directories(webots_driver PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
ament_target_dependencies(webots_driver
  rclcpp
  webots_ros2_driver
  pluginlib
  general_interface
  tf2
  std_msgs
  geometry_msgs
  nav_msgs)
target_link_libraries(webots_driver control_algorithm)

# Export the plugin configuration file
pluginlib_export_plugin_description_file(webots_ros2_driver robot_driver.xml)

# install targets
install(TARGETS webots_driver LIBRARY DESTINATION lib)

# Install launch files
install(
  DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch
)

# install sim files
install(
  DIRECTORY webots
  DESTINATION share/${PROJECT_NAME}/
)

add_executable(robot_kinematic_sim src/robot_kinematic_sim.cpp)
ament_target_dependencies(robot_kinematic_sim
  rclcpp
  general_interface
  tf2
  std_msgs
  geometry_msgs
  nav_msgs)
install(TARGETS robot_kinematic_sim RUNTIME DESTINATION lib/${PROJECT_NAME})

ament_package()
